package com.demo2do.fms.admin.entity.search.report;
import java.util.Date;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;

import com.demo2do.core.persistence.support.QueryBuilder;
import com.demo2do.core.persistence.support.QueryFilter;
import com.demo2do.core.persistence.support.QueryOrder;
import com.demo2do.core.utils.DateUtils;
import com.demo2do.fms.entity.supplier.common.Type;
import com.demo2do.fms.entity.vehicle.AuditStatus;

/**
 *
 * @author Ark
 *
 */
public class CostRevenueAnalysisSearch implements QueryBuilder {
	private Long organizationId;

	private Long customerId;

	private Long consignorId;
	
	private Long destWhId;

	private String destProvName;

	private String destCityName;
	
	private String isOutsourcing;
	
	@DateTimeFormat(pattern="yyyy-MM-dd")
	private String leavingStartDate;
	
	@DateTimeFormat(pattern="yyyy-MM-dd")
	private String leavingEndDate;
	
	private String loadNumber;

	private String loadGroupNumber;
	
	private String manufactorName;
	
	private Long outsourcingCompanyId;
	
	@DateTimeFormat(pattern="yyyy-MM-dd")
	private String shipmentStartDate;
	
	@DateTimeFormat(pattern="yyyy-MM-dd")
	private String shipmentEndDate;
	
	/**
	 * SRC_PROV_NAME	起始地所在省 string
	 */
	private String srcProvName;
	
	
	/**
	 * SRC_CITY_NAME	起始地城市 string
	 */
	private String srcCityName;
	

	/**
	 * SRC_WH_ID	起始地仓库ID long
	 */
	private Long srcWhId;
	
	/**
	 * 中文车牌号 VEHICLE_NAME
	 */
	private String vehicleName;
	
	private QueryOrder queryOrder;
    
    private QueryFilter queryFilter;

	/*
	 * (non-Javadoc)
	 * @see com.demo2do.core.persistence.support.QueryBuilder#getPreparedFilter(boolean)
	 */
	public QueryFilter getPreparedFilter(boolean refresh) {
		
	   Date ssd = DateUtils.parseDate(shipmentStartDate, "yyyy-MM-dd");
	   Date sed = DateUtils.parseDate(shipmentEndDate, "yyyy-MM-dd");
	   Date lsd = DateUtils.parseDate(leavingStartDate, "yyyy-MM-dd");
	   Date led = DateUtils.parseDate(leavingEndDate, "yyyy-MM-dd");		
		if(queryFilter == null || refresh) {
            queryFilter = new QueryFilter().addDateBetween("shipmentDate", ssd, sed)
									      .addDateBetween("leavingDate", lsd, led)
				            				.addEquals("customerId", customerId)
            							   .addEquals("companyId", organizationId)
            							   .addEquals("consignorId", consignorId)
            							   .addEquals("destWhId", destWhId)
            							   .addLike("destProvName", destProvName)
            							   .addLike("destCityName",destCityName)
            							   .addEquals("isOutsourcing",isOutsourcing)
            							   .addLike("loadNumber",loadNumber)
            							   .addLike("loadGroupNumber",loadGroupNumber)
            							   .addLike("manufactorName",manufactorName)
            							   .addEquals("outsourcingCompanyId",outsourcingCompanyId)
            							   .addLike("srcProvName",srcProvName)
            							   .addLike("srcCityName",srcCityName)
            							   .addEquals("srcWhId", srcWhId)
            							   .addLike("vehicleName", vehicleName);
        }
        
        return queryFilter;
	}

	/*
	 * (non-Javadoc)
	 * @see com.demo2do.core.persistence.support.QueryBuilder#buildSentenceTemplate()
	 */
	public String buildSentenceTemplate() {		
		
		String sentence = "FROM CostRevenueAnalysis "+getPreparedFilter(false).whereSentence();
		System.out.println("fms-sql : "+sentence);
        return sentence;
	}

	/* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildParameters()
     */
	public Map<String, Object> buildParameters() {
		return getPreparedFilter(false).parameters();
	}
	
	/*
	 * (non-Javadoc)
	 * @see com.demo2do.core.persistence.support.QueryBuilder#getOrder()
	 */
	public QueryOrder getOrder() {
		return queryOrder;
	}

	public Long getOrganizationId() {
		return organizationId;
	}

	public void setOrganizationId(Long organizationId) {
		this.organizationId = organizationId;
	}

	public Long getCustomerId() {
		return customerId;
	}

	public void setCustomerId(Long customerId) {
		this.customerId = customerId;
	}

	public Long getConsignorId() {
		return consignorId;
	}

	public void setConsignorId(Long consignorId) {
		this.consignorId = consignorId;
	}

	public Long getDestWhId() {
		return destWhId;
	}

	public void setDestWhId(Long destWhId) {
		this.destWhId = destWhId;
	}

	public String getDestProvName() {
		return destProvName;
	}

	public void setDestProvName(String destProvName) {
		this.destProvName = destProvName;
	}

	public String getDestCityName() {
		return destCityName;
	}

	public void setDestCityName(String destCityName) {
		this.destCityName = destCityName;
	}


	public String getIsOutsourcing() {
		return isOutsourcing;
	}

	public void setIsOutsourcing(String isOutsourcing) {
		this.isOutsourcing = isOutsourcing;
	}

	public String getLeavingStartDate() {
		return leavingStartDate;
	}

	public void setLeavingStartDate(String leavingStartDate) {
		this.leavingStartDate = leavingStartDate;
	}

	public String getLeavingEndDate() {
		return leavingEndDate;
	}

	public void setLeavingEndDate(String leavingEndDate) {
		this.leavingEndDate = leavingEndDate;
	}

	public String getLoadNumber() {
		return loadNumber;
	}

	public void setLoadNumber(String loadNumber) {
		this.loadNumber = loadNumber;
	}

	public String getLoadGroupNumber() {
		return loadGroupNumber;
	}

	public void setLoadGroupNumber(String loadGroupNumber) {
		this.loadGroupNumber = loadGroupNumber;
	}

	public String getManufactorName() {
		return manufactorName;
	}

	public void setManufactorName(String manufactorName) {
		this.manufactorName = manufactorName;
	}

	public Long getOutsourcingCompanyId() {
		return outsourcingCompanyId;
	}

	public void setOutsourcingCompanyId(Long outsourcingCompanyId) {
		this.outsourcingCompanyId = outsourcingCompanyId;
	}

	public String getShipmentStartDate() {
		return shipmentStartDate;
	}

	public void setShipmentStartDate(String shipmentStartDate) {
		this.shipmentStartDate = shipmentStartDate;
	}

	public String getShipmentEndDate() {
		return shipmentEndDate;
	}

	public void setShipmentEndDate(String shipmentEndDate) {
		this.shipmentEndDate = shipmentEndDate;
	}

	public String getSrcProvName() {
		return srcProvName;
	}

	public void setSrcProvName(String srcProvName) {
		this.srcProvName = srcProvName;
	}

	public String getSrcCityName() {
		return srcCityName;
	}

	public void setSrcCityName(String srcCityName) {
		this.srcCityName = srcCityName;
	}

	public Long getSrcWhId() {
		return srcWhId;
	}

	public void setSrcWhId(Long srcWhId) {
		this.srcWhId = srcWhId;
	}

	public String getVehicleName() {
		return vehicleName;
	}

	public void setVehicleName(String vehicleName) {
		this.vehicleName = vehicleName;
	}

	
	

	
}
